using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using FoundationLib.Ifc.Domain;


namespace FoundationLib.Ifc.Domain 
{
	/// <summary>
	/// Implementation of a container for pending events on an aggregate
	/// </summary>
	public sealed class PendingChanges : IPendingChanges
	{
		/// <summary>
		/// Internal list of pending changes
		/// </summary>
		private List<IVersionedEvent> changes;

		/// <summary>
		/// Creates a new pending changes instance
		/// </summary>
		internal PendingChanges()
		{
			this.changes = new List<IVersionedEvent>();
		}

		/// <summary>
		/// Adds a new domain event to the list of pending changes
		/// </summary>
		/// <param name="domainEvent">The domain event</param>
		public void Add(IVersionedEvent domainEvent)
		{
			this.changes.Add(domainEvent);
		}

		/// <summary>
		/// Clears the list of pending changes
		/// </summary>
		public void Clear()
		{
			this.changes.Clear();
		}

		/// <summary>
		/// Returns a typed enumerator for pending changes
		/// </summary>
		/// <returns>The typed pending changes enumerator</returns>
		public IEnumerator<IVersionedEvent> GetEnumerator()
		{
			return this.changes.GetEnumerator();
		}

		/// <summary>
		/// Returns an enumerator for pending changes
		/// </summary>
		/// <returns>The enumerator</returns>
		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable)this.changes).GetEnumerator();
		}
	}

}